// import feed from "~/utils/feed";

import axios from "axios";

const envConfig = require('dotenv').config({
  path: `.env${process.env.ENV ? `.${process.env.ENV}` : ''}`
})
//https://www.npmjs.com/package/js-yaml
// const fs   = require('fs');
console.log(envConfig)

export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  env: {
    ...process.env,
    ...envConfig.parsed,
    twikoo_env_id:'https://blog-issure.vercel.app/'
  },
  head: {
    title: '天道酬勤 - ZipFang ` Blog',
    htmlAttrs: {
      lang: 'cn'
    },
    meta: [
      {charset: 'utf-8'},
      {name: 'viewport', content: 'width=device-width, initial-scale=1'},
      {hid: 'description', name: 'description', content: '木之下，分享工作中所遇到的技术难点，以及生活中的奇闻趣事。'},
      {name: 'format-detection', content: 'telephone=no'},
      {hid: 'keywords', name: 'keywords', content: '个人网站，木之下，个人博客，博客，原创博客网站'}
    ],
    link: [
      {rel: 'icon', type: 'image/x-icon', href: '/favicon.png'},
      // {
      //   rel: 'stylesheet',
      //   href: 'https://cdn.jsdelivr.net/gh/616620131/photo-page-for-typecho@2.0/Multiverse/css/fontawesome-all.min.css'
      // },
      // {
      //   rel: 'stylesheet',
      //   href: 'https://cdn.jsdelivr.net/npm/vditor@3.8.4/dist/js/highlight.js/styles/monokai.css'
      // },
      {
        rel: 'stylesheet',
        href: 'https://at.alicdn.com/t/font_1808991_t6xnm56v3l.css'
      }
    ],
    script: [
      {src: "https://cdn.bootcss.com/headroom/0.9.1/headroom.min.js"},
      //{src:"https://cdn.jsdelivr.net/combine/npm/pace-js@1.0.2/pace.min.js,npm/pjax@0.2.8/pjax.min.js,npm/whatwg-fetch@3.4.0/dist/fetch.umd.min.js,npm/animejs@3.2.0/lib/anime.min.js,npm/algoliasearch@4/dist/algoliasearch-lite.umd.js,npm/instantsearch.js@4/dist/instantsearch.production.min.js,npm/lozad@1/dist/lozad.min.js,npm/quicklink@2/dist/quicklink.umd.js",body: true}
      // 友盟收费啦 使用百度统计试下吧 哈哈
      //{src: "https://s9.cnzz.com/z_stat.php?id=1280376854&web_id=1280376854"}
    ]
  },

  srcDir: 'src/',

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    // 只有相册页面用到 但是老是cdn异常 暂时不引人了
    //'@/assets/css/fontawesome-all.min.css',
    '@/assets/css/variable.scss',
    '@/assets/css/base.scss',
    '@/assets/css/monokai.css',
    '@/assets/css/style.min.scss',
    '@/assets/css/font-awesome.min.css',
    '@/assets/css/DoubanBoard.css',
    '@/assets/css/top-style.scss',
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [

    '@/plugins/i18n.js',
    '@/plugins/filters.js',
    "@/plugins/config.js",
    {src: '@/plugins/twikoo.js', ssr: false},
    {src: '@/plugins/aplayer.js', ssr: false},
    {src: '@/plugins/lazyload.js', ssr: false}
    // {src: '~/plugins/i18n.js', mode: 'server'},
    // {src: '~/plugins/filters.js', mode: 'server'},
  ],

  styleResources:{
    scss:[
      './src/assets/css/variable.scss'
    ]
  },

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  // buildModules: [
  //   // https://go.nuxtjs.dev/eslint
  //   '@nuxtjs/eslint-module',
  // ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    'cookie-universal-nuxt',
    '@nuxtjs/feed',
    '@nuxtjs/style-resources', // 添加对应的模块
  ],
  feed: [
    // Your feeds
    {
      path: '/feed.xml', // The route to your feed.
      async create(feed) {
        feed.options = {
          title: '木之下',
          link: envConfig.parsed.BASE_HOST,
          description: '木之下博客，分享工作中所遇到的技术难点，以及生活中的奇闻趣事。'
        }
        const posts = await axios.get(envConfig.parsed.BASE_URL + '/article/get',{
          params:{pageNo:1, pageSize: 100, cmd: 1}
        })
        if(posts.data.code === 200) {
          posts.data.data.forEach(post => {
            feed.addItem({
              title: post.articleTitle,
              id: post.oId,
              link: envConfig.parsed.BASE_HOST + `/article-detail/${post.oId}`,
              description: post.articleAbstractText,
              content: post.articleAbstractText
            })
          })
        }
        //
        feed.addCategory('Nuxt.js')

        feed.addContributor({
          name: 'ZiPing Fang',
          email: '768449566@qq.com',
          link: envConfig.parsed.BASE_HOST
        })

      }, // The create function (see below)
      cacheTime: 1000 * 60 * 15, // How long should the feed be cached
      type: 'rss2', // Can be: rss2, atom1, json1
      data: ['Some additional data'] // Will be passed as 2nd argument to `create` function
    }
  ],
  loading: false,
  // Axios module configuration: https://go.nuxtjs.dev/config-axios
  axios: {
    // Workaround to avoid enforcing hard-coded localhost:3000: https://github.com/nuxt-community/axios-module/issues/308
    baseURL: envConfig.parsed.BASE_URL,
  },

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    vendor: ['external_library']
  },
  router: {
    //middleware: 'i18n'
    middleware: 'stats'
  },
  server: {
    port: envConfig.parsed.NUXT_ENV_BASE_PORT,
    host: envConfig.parsed.NUXT_ENV_HOST
  },

}
